using UnityEngine;

public class RelicViewCreator_ban : PersistentSingleton<RelicViewCreator_ban >
{
    private string path = "Prefabs/RelicView/";

    // 核心方法：生成 RelicView，并挂在父物体下
    private RelicView InstantiateRelicView(Relic relicData, Transform parent)
    {
        if (relicData == null || parent == null)
            return null;

        string fullPath = path + relicData.Title;
        RelicView prefab = Resources.Load<RelicView>(fullPath);
        if (prefab == null)
        {
            Debug.LogError($"Prefab not found at path: Resources/{fullPath}");
            return null;
        }

        // 在 parent 下实例化，并重置本地坐标/旋转/缩放
        RelicView relicView = Instantiate(prefab, parent);
        relicView.transform.localPosition = Vector3.zero;
        relicView.transform.localRotation = Quaternion.identity;
        relicView.transform.localScale = Vector3.one;

        relicView.Setup(relicData);
        Debug.Log($"[RelicViewCreator] Loading prefab: {fullPath}, ShowTitle={ (relicData as Relic)?.ShowTitle }");
        return relicView;
    }

    // 对外方法：接受 GameObject
    public RelicView CreateRelicView(Relic relicData, GameObject viewSlot)
    {
        return InstantiateRelicView(relicData, viewSlot?.transform);
    }

    // 对外方法：接受 Transform
    public RelicView CreateRelicView(Relic relicData, Transform viewSlot)
    {
        return InstantiateRelicView(relicData, viewSlot);
    }

    // 对接口兼容的方法
    public IBagItemView CreateView(object relicData, Transform viewSlot)
    {
        return InstantiateRelicView((Relic)relicData, viewSlot);
    }
}
